<?php
define('CACHE_LIVE_TIME', 3600 * 24 * 30);
define('READ_CACHE',true);
class Cache
{
	private static $memcache = null;
	private function __construct(){
	
	}
	static function getInstance()
	{
		if(self::$memcache == null){
			$memConfig 		= 	ConfigReaderFactory::getInstance()->getConfigReader(AC::MEM_CONFIG_FILE)->getConfig();
			$data			=	$memConfig->xpath('mem');
			$memcache 	= 	new Memcache();
			for($i = 0; $i < count($data); $i++){
				
				$server	=	(string) $data[$i]->server;
				$port	=	intval($data[$i]->port);
				$memcache->addServer($server, $port);
			}
			self::$memcache	=	$memcache;
		}
		return self::$memcache;
	}
	public static function get($key){
		if(READ_CACHE){
			$cache	=	self::getInstance();
			return $cache->get($key);
		}else{
			return false;
		}
	}
	public static function set($key, $value, $second = CACHE_LIVE_TIME){
		
		$cache	=	self::getInstance();
		return $cache->set($key, $value, 0, $second);
	}
}